#include "WaterEnemyEntity.h"
#include "EffectManager.h"



void WaterEnemyEntity::_updateSprites()
{
	if (_armyData->delayBeforeShoot > 0) {
		_armyData->sprites->setState(STATE_ASSIGN);
		_armyData->delayBeforeShoot--;
		if (_armyData->delayBeforeShoot <= 0) {
			_armyData->delayForShoot = 30;
		}
	}

	if (_armyData->delayForShoot > 0) {
		_armyData->sprites->setState(STATE_SHOOTING);
		if (_armyData->delayForShoot == 30) {
			_readyForShoot();
		}
		_armyData->delayForShoot--;
		if (_armyData->delayForShoot <= 0) {
			_armyData->delayBeforeShoot = 150;
		}
	}
}

void WaterEnemyEntity::_readyForShoot()
{
	if (_armyData->bulletContainer->checkCanFire()) {
		_armyData->bulletContainer->fire(_armyData->getRect()->X, _armyData->getRect()->Y + 20, _BULLET_DIRECTION_UP, NULL);
	}
}

WaterEnemyEntity::WaterEnemyEntity(int id, int type, double x, double y)
{
	_armyData = new WaterEnemyData(id, type, x, y);
}

WaterEnemyEntity::WaterEnemyEntity(WaterEnemyData* armyData)
{
	_armyData = armyData;
}

void WaterEnemyEntity::draw(long timetick)
{
	if (_armyData->isDead) return;
	_armyData->sprites->draw();
	_armyData->bulletContainer->draw(0);
}

void WaterEnemyEntity::update(long timetick)
{
	if (_armyData->isDead) return;
	_updateSprites();
	_armyData->sprites->updateCurrent();
	_armyData->bulletContainer->update(0);
}

AbstractData* WaterEnemyEntity::getAbstractData()
{
	return _armyData;
}

void WaterEnemyEntity::updateData(int action ,int dataaction)
{
	_armyData->isDead = true;
	_armyData->canInteract = false;
	EffectManager::getInstatnse()->createEffect(EffectType::TYPE_Object_Burning, _armyData->rect->X, _armyData->rect->Y);
}
